{{ define "board" }}<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>/{{.BoardName}}/</title>
        <link rel="stylesheet" type="text/css" href="/static/board.css" />
        <script type="text/javascript" src="/static/general.js"></script>
    </head>

    <body>
        {{ template "header" . }}
        <section id="middle">
            {{ range .Threads }} {{ template "summary" . }} {{ end }}
        </section>
        {{ template "board_footer" . }}
    </body>
</html>
{{ end }}

{{define "thread"}}<!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>/{{.BoardName}}/</title>
            <link rel="stylesheet" type="text/css" href="/static/board.css" />
            <script type="text/javascript" src="/static/general.js"></script>
        </head>

        <body>
            {{ template "header" . }}
            <section id="middle">
                {{ $t := index .Threads 0 }}
                {{template "summary" $t }}
                {{ if $t.Expired }}
                    <div class="info">Crawler received 404 status from thread as of {{ $t.Expired }}.</div>
                {{ end }}
            </section>
            <footer>
                <nav id="jump">[ <a href="/{{.BoardName}}/">Return</a> ] [ <a href="#top">Top</a> ] </nav>
                <form id="add_post" name="add_post" action="/{{.BoardName}}/post" method="POST">
                    <table id="post_table" border="0">
                        <tr>
                            <td><label for="subject">Subject:</label></td>
                            <td colspan="4"><input id="subject" name="subject" type="text"/></td>
                        </tr>
                        <tr id="comment_row">
                            <td><label for="comment">Comment:</label></td>
                            <td colspan="4"><textarea id="comment" name="comment" rows="5"></textarea></td>
                        </tr>
                        <tr> 
                            <td><label for="name">Name:</label></td>
                            <td><input id="name"  name="name" type="text" autocomplete="on"/></td>
                            <td><label for="name">Email:</label></td>
                            <td><input id="email" name="email" type="text" autocomplete="on"/></td>
                            <td><input type="submit" value="Submit"/></td>
                            <td><input name="thread_no" type="hidden" value="{{ $t.OpIntId.Int64 }}"/></td>
                        </tr>
                    </table>
                </form>
                {{ template "buttons" . }}
                {{ template "board_list" . }}
                <div class="info">Page generated {{.Generated}} ({{ .TimeElapsed }} ms)</div>
            </footer>
        </body>
    </html>
{{end}}

{{ define "header" }}
    <header>
        <a id="top"></a>
        <form name="ghost_mode" id="ghost_mode" action="/{{ .BoardName }}/ghost_mode"></form>
        <form name="reported_posts" id="reported_posts" method="POST" action="/{{ .BoardName }}/report_landing"></form>
        {{ template "board_list" . }}
        {{ template "search" . }}
        <h2 id="title">/{{ .BoardName }}/ - {{.Title}}</h2>
        {{ template "buttons" . }}
    </header>
{{ end }}

{{ define "summary" }}
    <hr/>
    <section class="thread">
    {{ $thread := . }}{{ with .Head }}
        {{ if .ImgIntId.Valid }}
            <div class="img_info">File: {{ .ImgName.String }} {{ .Img.Size.Int64 }}, {{ .Img.FullX.Int64 }}x{{ .Img.FullY.Int64 }} [View same] [iqdb] [google]</div>
            <a id="a_{{ .PostId.Int64 }}"></a>
            {{ if .Img.ImgFile.Valid }}
                <a href="/static/img/{{ .Img.ImgFile.String }}" alt="{{ .ImgName.String }}">
            {{ else }}
                <a href="/redirect/{{ .FmtImgUrl }}" alt="{{ .ImgName.String }}">
            {{ end }}
                <img src="/static/thumb/{{.Img.ThumbFile.String}}" alt="{{.ImgName.String }}" class="post_image"/>
            </a>
        {{ end }}
        <div class="post_info">
            <input type="checkbox" name="{{ .IntId.Int64 }}|=|{{ .Parent.Int64 }}|=|{{ .PostId.Int64 }}" form="reported_posts" value="true" />
            <span class="subject">{{ .Subject.String }}</span>
            <span class="{{ .Auth.String }}">
                {{ if eq .Mail.String "" | not }}
                    <a class="bold" href="mailto:{{.Mail.String}}">{{ .Name.String }}</a>
                {{ else }}
                    <span class="bold">{{ .Name.String }}</span>
                {{ end }}

                <span class="trip">{{ .Trip.String }}</span>
                {{ if eq .Auth.String "user" | not }}
                    <span class="bold">
                             ## {{ .Auth.String }}
                            <img src="/static/ui_img/{{ .Auth.String }}.gif" alt="{{ .Auth.String }} user." />
                    </span>
                {{ end }}
            </span>
            <span class="time">{{ .FmtTime }}</span>
            <a href="res/{{ .PostId.Int64 }}#a_{{ .PostId.Int64 }}" class="post_no">No.{{ .PostId.Int64 }}</a>
            {{ if $thread.FullThread | not }}
                 [<a href="res/{{ .PostId.Int64 }}">Reply</a>]
            {{ end }}
             [<a href="{{ $thread.ThreadUrl.String }}">Original</a>]
            {{ if $thread.Sticky.Bool }} <img src="/static/ui_img/sticky.gif" alt="Thread was stickied."/> {{ end }}
            {{ if $thread.Locked.Bool }} <img src="/static/ui_img/locked.gif" alt="Thread was locked."/> {{ end }}
            {{ if $thread.Deleted.Bool }}<span class="delete_mark">✖</span>{{ end }}
        </div>
        <div class="op_text">
        <blockquote>{{ .EscapedBody }}</blockquote>
        {{ $pOmit := $thread.PostsOmitted.Int64 }}
        {{ $iOmit := $thread.ImgsOmitted.Int64 }}
        {{ if $thread.Deleted.Bool }}
            <div class="red info">Thread missing as of {{ $thread.Expired }}.</div>
        {{ end }}
        {{ if $thread.PostsOmitted.Int64 }}
        <b>
            {{ $pOmit }} post{{ if eq $pOmit 1 | not }}s{{end}}
            {{ if $iOmit }}
                 and {{ $iOmit }} image replie{{ if eq $iOmit 1 | not }}s{{end}}
            {{ end }}
            omitted. Click Reply to view.
        </b>
        {{ end }}
        </div>
    {{ end }}

    {{ range .Tail }} {{ template "tail" . }} {{ end }}
    </section>
{{ end }}


{{ define "tail" }}
    <div class="post_container">
        <article class="{{ .FmtClass }}">
            <div class="post_info">
                <a id="a_{{ .FmtPostNo }}"></a>
                <input type="checkbox" name="{{ .IntId.Int64 }}|=|{{ .Parent.Int64 }}|=|{{ .PostId.Int64 }}" form="reported_posts" value="true" />
                <span class="subject">{{ .Subject.String }}</span>

                <span class="{{ .Auth.String }}">
                    {{ if eq .Mail.String "" | not }}
                        <a class="bold" href="mailto:{{.Mail.String}}">{{ .Name.String }}</a>
                    {{ else }}
                        <span class="bold">{{ .Name.String }}</span>
                    {{ end }}

                    <span class="trip">{{ .Trip.String }}</span>
                    <span class="bold">
                        {{ if eq .Auth.String "user" | not }}
                             ## {{ .Auth.String }}
                            <img src="/static/ui_img/{{ .Auth.String }}.gif" alt="{{ .Auth.String }} user." />
                        {{ end }}
                    </span>
                </span>
                <span class="time">{{ .FmtTime }}</span>
                <a href="res/{{.Parent.Int64}}#a_{{ .FmtPostNo }}" class="post_no">No.{{ .FmtPostNo }}</a>
                {{ if .PostDeleted }}<span class="delete_mark">✖</span>{{ end }}
                {{ if .GhostId.Valid }}<span class="ghost_mark">✴</span>{{ end }}
            </div>

            {{ if .ImgIntId.Valid }}
                <div class="img_info">File: {{ .ImgName.String }} {{ .Img.Size.Int64 }}, {{ .Img.FullX.Int64 }}x{{ .Img.FullY.Int64 }} [View same] [iqdb] [google]</div>
                {{ if .Img.ImgFile.Valid }}
                    <a href="/static/img/{{ .Img.ImgFile.String }}" alt="{{ .ImgName.String }}">
                {{ else }}
                    <a href="/redirect/{{ .FmtImgUrl }}" alt="{{ .ImgName.String }}" rel="noreferrer">
                {{ end }}
                    <img src="/static/thumb/{{.Img.ThumbFile.String}}" alt="{{.ImgName.String }}" class="post_image"/>
                </a>
            {{ end }}
            <blockquote>{{ .EscapedBody }}</blockquote>
            {{ if .PostDeleted }}<div class="right red info">Post not found as of {{ .FmtPostDel }}</div>{{ end }}
        </article>
    </div>
{{ end }}

{{ define "board_list" }}
    <div>
        {{ $final := len .Boards | add -1 | index .Boards }}
        [
        {{ range .Boards }} 
        <a href="/{{ . }}/">{{ . }}</a> {{ if eq $final . | not }} / {{ end }}
        {{ end }} 
        ]
        [ <a href="/">Home</a> ]
    </div>
{{ end }}


{{ define "board_footer" }}
    <footer>
    {{ template "page_list" . }}
    <div>{{ template "board_list" . }}</div>
    <div class="info">Page generated {{ .Generated }} (query/construction: {{ .TimeElapsed }} ms)</div>
    </footer>
{{ end }}

{{ define "search" }}
    <form name="search_box" id="search_box" action="/{{ .BoardName }}/search">
        <table id="search_table">
            <tr>
                <td><label for="text_search">Body:</label></td>
                <td><input id="text_search" name="text_search" value="{{.Search.text_search}}" 
                    type="search" placeholder="Comment Text" autocomplete="on"/>
                </td>
                <td><label for="subject_search">Subject:</label></td>
                <td><input id="subject_search" name="subject_search" value="{{.Search.subject_search}}"
                    type="search" placeholder="Subject"/></td>
                <td><label for="file_name" >File:</label></td>
                <td><input id="file_name" name="file_name" value="{{.Search.file_name}}"
                    type="search" placeholder="File Name"/></td>
                <td rowspan="2" valign="middle">
                    <input type="submit" value="Search"/>
                </td>
            </tr>
            <tr> 
                <td><label for="post_id">Post#:</label></td>
                <td><input id="post_id" name="post_id" value="{{.Search.post_id}}"
                     type="search" placeholder="Post Number"/></td>
                <td><label for="user_name" >Name:</label></td>
                <td><input id="user_name" name="user_name" value="{{.Search.user_name}}"
                     type="search" placeholder="User Name"/></td>
                <td><label for="trip" >Trip:</label></td>
                <td><input id="trip" name="trip" value="{{.Search.trip}}"
                     type="search" placeholder="Tripcode"/></td>
                <tr>
        </table>
    </form>
{{ end }}

{{ define "page_list" }}
    {{ $base   := .PageBase }}
    {{ $curPage := .PageNo }}
    {{ $nearEnd := .NearEnd }}
    <div class="post_container">
        <nav id="page_list">
        {{ if eq $curPage 0 | not }}
            <a href="{{ $base }}{{add $curPage -1}}" class="arrow">&lt;&lt;</a>
        {{ end }}
        {{ range .Pages }}
            {{ if eq . $curPage }} [{{ . }}] {{ else }} <a href="{{ $base }}{{.}}" class="page">[{{.}}]</a> {{ end }}
        {{ end }}
        {{ if $nearEnd | not }}
            <a href="{{ $base }}{{add $curPage 1}}" class="arrow">&gt;&gt;</a>
        {{ end }}
        </nav>
        {{ template "buttons" . }}
    </div>
{{ end }}

{{ define "buttons" }}
    <div class="report_button">
        <input type="submit" form="ghost_mode" value="Ghost Mode"/>
        <input type="submit" form="reported_posts" value="Report Posts"/>
    </div>
{{ end }}
